<template>
	<view class="p-20">
		<view class="bg-white p-30 border-radius">
			<view class="form-item mb-40">
				<view class="font-bold font-28">公司名称</view>
				<view class="mt-20">
					<uni-easyinput v-model="form.name" placeholder="请输入公司名称" />
				</view>
			</view>
			<view class="form-item mb-40">
				<view class="font-bold font-28">公司所在地</view>
				<view class="mt-20">
					<uni-data-select v-model="form.city" :localdata="city_enum" @change="change"></uni-data-select>
				</view>
			</view>
			<view class="form-item mb-40">
				<view class="font-bold font-28">公司logo</view>
				<view class="mt-20 flex items-center flex-wrap">
					<view class="add-btn mr-20" @click="ChooseImage('logo')">
						<uni-icons type="plusempty" size="30" color="#777"></uni-icons>
					</view>
					<image @click="delect('logo')" v-if="form.logo !== ''" class="mr-20" :src="imgUrl+form.logo" mode="" style="width: 180rpx;height: 180rpx;">
					</image>
				</view>
			</view>
			<view class="form-item mb-40">
				<view class="font-bold font-28">公司行业</view>
				<view class="mt-20">
					<uni-data-select v-model="form.companyProfession" :localdata="profession_category"
						@change="change"></uni-data-select>
				</view>
			</view>
			<view class="form-item mb-40">
				<view class="font-bold font-28">公司简介</view>
				<view class="mt-20">
					<uni-easyinput type="textarea" v-model="form.intro" placeholder="请输入公司简介" />
					<!-- <mp-html :content="form.intro" /> -->
					<!-- <editor id="editor" class="ql-container" placeholder="开始输入..." show-img-size show-img-toolbar
						show-img-resize @statuschange="onStatusChange" @ready="onEditorReady">
					</editor> -->
				</view>
			</view>

			<view class="form-item mb-40">
				<view class="font-bold font-28">公司规模/人</view>
				<view class="mt-20">
					<uni-easyinput v-model="form.scale" placeholder="请输入公司规模" />
				</view>
			</view>
			<view class="form-item mb-40">
				<view class="font-bold font-28">公司详细地址</view>
				<view class="mt-20">
					<uni-easyinput v-model="form.address" placeholder="请输入公司详细地址" />
					<view class="map-btn" @click="showMyMap = true">地图选点</view>
				</view>
			</view>
			<view class="form-item mb-40">
				<view class="font-bold font-28">营业执照</view>
				<view class="mt-20 flex items-center flex-wrap">
					<view class="add-btn mr-20" @click="ChooseImage('license')">
						<uni-icons type="plusempty" size="30" color="#777"></uni-icons>
					</view>
					<image @click="delect('license')" v-if="form.license !== ''" class="mr-20" :src="imgUrl+form.license" mode="" style="width: 180rpx;height: 180rpx;">
					</image>
				</view>
			</view>
		</view>

		<view class="bottom-view">
			<view class="bottom-btn font-white bg-g" @click="submit">提交信息</view>
		</view>
		
		<mmap :show="showMyMap" @getMapAddress="getMapAddress"></mmap>
	</view>
</template>

<script>
	import {mmap} from '@/components/mls-map/mmap.vue'
	import {
		getInfo
	} from '../../api/hr_user';
	import {
		queryById,
		add,
		edit
	} from '../../api/company';

	import {
		getCategory
	} from '../../api/common.js';
	import { BASE_URL } from '../../utils/constant';
	export default {
		components: {mmap},
		data() {
			return {
				showMyMap: false,
				job_nature: [{
					text: '全职',
					value: 0
				}, {
					text: '兼职',
					value: 1
				}, {
					text: '实习',
					value: 2
				}, {
					text: '校园',
					value: 3
				}],
				education_enum: [{
					text: '初中及以下',
					value: '初中及以下'
				}, {
					text: '中专/中技',
					value: '中专/中技'
				}, {
					text: '高中',
					value: '高中'
				}, {
					text: '大专',
					value: '大专'
				}, {
					text: '本科',
					value: '本科'
				}, {
					text: '硕士',
					value: '硕士'
				}, {
					text: '博士',
					value: '博士'
				}],
				experience_enum: [{
					text: '实习',
					value: '实习'
				}, {
					text: '1年以内',
					value: '1年以内'
				}, {
					text: '1-3年',
					value: '1-3年'
				}, {
					text: '3-5年',
					value: '3-5年'
				}, {
					text: '5年以上',
					value: '5年以上'
				}],
				city_enum: [{
					text: '东营市',
					value: '东营市'
				}, {
					text: '河口区',
					value: '河口区'
				}, {
					text: '垦利区',
					value: '垦利区'
				}, {
					text: '广饶县',
					value: '广饶县'
				}, {
					text: '利津县',
					value: '利津县'
				}],
				form: {
					status: 1,
					logo: '',
					license: ''
				},
				isEdit: true,

				profession_category: [],
				imgUrl: BASE_URL+ '/jeecg-boot/sys/common/static/'
			};
		},
		onLoad() {
			this.getHr()
			this.getCate2()
		},
		methods: {
			getMapAddress(data) {
				console.log(data)
				this.form.address = data.address
				this.form.latitude = data.location.lat
				this.form.longitude = data.location.lng
				this.showMyMap = false
			},
			getCate2() {
				getCategory({
					pcode: 'profession_category'
				}).then(res => {
					const profession_category = res.result
					for (let x in profession_category) {
						this.profession_category.push({
							value: profession_category[x].title,
							text: profession_category[x].title,
						})
					}
				})
			},
			getHr() {
				const _this = this
				getInfo().then(res => {
					if (res.code === 200) {
						this.form.companyId = res.result.companyId
						this.getCompany()
					} else {
						this.isEdit = false
					}
				})
			},
			getCompany() {
				queryById({
					id: this.form.companyId
				}).then(res => {
					this.form = res.result
				})
			},
			submit() {
				const _this = this
				this.$tips.showModal('是否提交信息？', () => {
					if (this.isEdit) {
						edit({
							...this.form
						}).then(res => {
							if (res.code === 200) {
								_this.$tips.showConfirmModal('提交成功，请等待审核', () => {
									uni.navigateBack()
								})
							} else {
								_this.$tips.showConfirmModal('提交失败，请重试', () => {})
							}
						})
					} else {
						add({
							...this.form
						}).then(res => {
							if (res.code === 200) {
								uni.setStorageSync('companyId', res.result)
								_this.$tips.showConfirmModal('提交成功，请等待审核', () => {
									uni.navigateBack()
								})
							} else {
								_this.$tips.showConfirmModal('提交失败，请重试', () => {})
							}
						})
					}
				})
			},
			ChooseImage(names) {
				var _this = this;
				uni.chooseImage({
					count: 1, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album', 'camera'], //从相册选择和拍照
					success: (res) => {
						var tempFilePath = res.tempFilePaths[0];
						uni.uploadFile({
							url: BASE_URL + '/jeecg-boot/sys/common/upload', //上传的服务器地址
							filePath: tempFilePath,
							method: 'POST',
							header: {
								'Authorization': this.$storage.getStorageSync('token'),// 在拦截器配置token之类的header操作，防止首次加载token后，读取不到token
								'X-Access-Token': this.$storage.getStorageSync('token')// 在拦截器配置token之类的header操作，防止首次加载token后，读取不到token
							},
							name: "file",
							success: res => {
								const resd = JSON.parse(res.data)
								console.log(resd)
								if (resd.success) {
									this.form[names] = resd.message
								} else {
									this.$tips.showConfirmModal('图片上传失败')
								}
							}
						});
					}
				});
			},
			//查看图片
			// lookImg: function(val) {
			// 	const current = val
			// 	uni.previewImage({
			// 		[BASE_URL+'/jeecg-boot/sys/common/static/'+this.form.credential],
			// 		current
			// 	})
			// },
			delect(names) {
				uni.showModal({
					title: "提示",
					content: "是否要删除该图片",
					success: (res) => {
						if (res.confirm) {
							this.form[names] = ''
						}
					}
				})
			},
		}
	}
</script>

<style lang="less">
	page {
		background-color: #f6f6f6;
		padding-bottom: 200rpx;
	}

	.bottom-view {
		width: 100vw;
		padding: 40rpx 0;
		background-color: #fff;
		position: fixed;
		bottom: 0;
		left: 0;
		z-index: 99999;
		border-top: 1px solid #efefef;

		.bottom-btn {
			width: 80vw;
			margin: auto;
			text-align: center;
			border-radius: 50rpx;
			padding: 20rpx 0;
		}
	}

	.add-btn {
		width: 180rpx;
		height: 180rpx;
		border: 1px solid #777;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.map-btn {
		margin-top: 20px;
		color: red;
		font-size: 22rpx;
		padding: 10rpx 0;
		border: 1px solid red;
		border-radius: 20rpx;
		text-align: center;
	}
</style>